package com.ruoyi.web.controller.ui;

import com.ruoyi.answer.domain.QtAnswer;
import com.ruoyi.answer.service.IQtAnswerService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.exam.domain.QtExam;
import com.ruoyi.exam.service.IQtExamService;
import com.ruoyi.paper.domain.QtPaper;
import com.ruoyi.paper.service.IQtPaperService;
import com.ruoyi.qt.domain.QtNote;
import com.ruoyi.qt.domain.QtRecord;
import com.ruoyi.qt.domain.QtScore;
import com.ruoyi.qt.service.IQtNoteService;
import com.ruoyi.qt.service.IQtRecordService;
import com.ruoyi.qt.service.IQtScoreService;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam/tk")
public class TkController extends BaseController {
    @Autowired
    IQtChapterService iQtChapterService;
    @Autowired
    IQtUsesrCourseService iQtUsesrCourseService;
    @Autowired
    IQtCourseService iQtCourseService;
    @Autowired
    IQtTkService iQtTkService;
    @Autowired
    IQtPaperService iQtPaperService;
    @Autowired
    IQtOptionService iQtOptionService;
    @Autowired
    IQtRecordService iQtRecordService;
    @Autowired
    private IQtNoteService qtNoteService;
    @Autowired
    private IQtAnswerService qtAnswerService;
    @Autowired
    private IQtExamService qtExamService;
    @Autowired
    IQtPaperService qtPaperService;
    @Autowired
    private IQtScoreService qtScoreService;
    /**
     * 查询章节管理列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody QtChapter qtChapter)
    {
        List<QtChapter> list = iQtChapterService.selectQtChapterList(qtChapter);
        return getDataTable(list);
    }
    @PostMapping("CourseList")
    public  TableDataInfo courseList(@RequestBody  QtUsesrCourse qtUsesrCourse){
        List<QtUsesrCourse> list=iQtUsesrCourseService.selectQtUsesrCourseList(qtUsesrCourse);
        return getDataTable(list);
    }
    @RequestMapping("/Course")
    public TableDataInfo course(@RequestBody QtCourse qtCourse){
        List<QtCourse> list=iQtCourseService.selectQtCourseList(qtCourse);
        return getDataTable(list);
    }
    @RequestMapping("/getTk")
    public  TableDataInfo getTk(@RequestBody QtTk qtTk){
        List<QtTk> list=iQtTkService.selectQtTkList(qtTk);
        QtOption option=new QtOption();
        for(QtTk item:list){
            option.setTkId(item.getTkId());
            item.setOptions(iQtOptionService.getOptions(option));
        }
        return getDataTable(list);
    }
    @PostMapping("/save")
    public AjaxResult save(@RequestBody QtRecord qtRecord){
        iQtRecordService.deleteQtRecordByRecordId(qtRecord);
        qtRecord.setRecordId(IdUtils.randomUUID());
        return toAjax(iQtRecordService.insertQtRecord(qtRecord));
    }
    @PostMapping("/getRecord")
    public TableDataInfo getRecord(@RequestBody QtRecord qtRecord)
    {
        List<QtRecord> list = iQtRecordService.selectQtRecordList(qtRecord);
        return getDataTable(list);
    }
    @PostMapping("saveNote")
    public AjaxResult saveNote(@RequestBody QtNote qtNote)
    {
        qtNote.setNoteId(IdUtils.randomUUID());
//        qtNote.setNoteTime(getTime());
        return toAjax(qtNoteService.insertQtNote(qtNote));
    }

    @PostMapping("/noteList")
    public TableDataInfo noteList(@RequestBody QtNote qtNote)
    {
        startPage();
        List<QtNote> list = qtNoteService.selectQtNoteList(qtNote);
        return getDataTable(list);
    }
    @PostMapping("/answerList")
    public TableDataInfo answerList(@RequestBody QtAnswer qtAnswer)
    {
        startPage();
        List<QtAnswer> list = qtAnswerService.selectQtAnswerList(qtAnswer);
        return getDataTable(list);
    }
    @PostMapping("/saveAnswer")
    public AjaxResult saveAnswer(@RequestBody QtAnswer qtAnswer)
    {
        return toAjax(qtAnswerService.insertQtAnswer(qtAnswer));
    }

    @PostMapping("/examList")
    public TableDataInfo examList(@RequestBody QtExam qtExam)
    {
//        startPage();
        List<QtExam> list = qtExamService.selectQtExamList(qtExam);
        return getDataTable(list);
    }
    @PostMapping("/getTk1")
    public List<QtTk> getTk1(@RequestBody QtPaper qtPaper){
        return qtPaperService.getTk(qtPaper);
    }

//    交卷
    @PostMapping("jiaojuan")
    public AjaxResult jiaojuan(@RequestBody QtScore qtScore)
    {
        return toAjax(qtScoreService.updateQtScore(qtScore));
    }
}
